#ifndef BUFFERFRAME_H
#define BUFFERFRAME_H

#include "Semaphore.h"

class BufferFrame
{
public:
    BufferFrame(BufferFrame& other) = delete;
    BufferFrame operator=(BufferFrame& other) = delete;

    bool isDirty();
    void markDirty(bool dirty);
    void* getData();
    unsigned getPageId();
    void doLock(bool exclusive);
    int tryLock();
    void releaseLock();
    const bool operator<(const BufferFrame& other);

protected:

private:
    unsigned pageId;
    bool dirty;
    char* data;
    bool secondChance;
    bool isDummyFrame;
    SEMAPHORE pageLock;

    BufferFrame(unsigned pageID, char* data);
    BufferFrame(unsigned pageID, char* data, bool secondChance, bool isDummy);
    ~BufferFrame();

    bool hasSecondChance();
    void setSecondChance(bool chance);
    bool isDummy();

    friend class BufferManager;
    friend class SingleBufferManager;
    friend class SortedBufferManager;
};

#endif // BUFFERFRAME_H
